﻿using AutoMapper;
using Domain.Entity;
using Domain.Entity.ord;
using Domain.IRepository;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Application.PurchaseReturn_hService
{
    public class PurchaseReturn_hService : IPurchaseReturn_hService
    {
        private readonly IPurchaseReturn_hRepository purchaseReturn_HRepository;
        private readonly IMapper mapper;

        public PurchaseReturn_hService(IPurchaseReturn_hRepository purchaseReturn_HRepository,IMapper mapper)
        {
            this.purchaseReturn_HRepository = purchaseReturn_HRepository;
            this.mapper = mapper;
        }

        //添加进货退货单
        public async Task<int> AddPurchaseReturn_h(AddPurchaseReturn_hDto addPurchaseReturn_HDto)
        {
            PurchaseReturn_h purchaseReturn_H = mapper.Map<PurchaseReturn_h>(addPurchaseReturn_HDto);
            return await purchaseReturn_HRepository.AddPurchaseReturn_h(purchaseReturn_H);
        }


        //审核
        public async Task<int> ApproverPurchaseReturn_h(int purtid, int status, string approvername, string approvertime)
        {
            return await purchaseReturn_HRepository.ApproverPurchaseReturn_h(purtid, status, approvername, approvertime);
        }


        //删除
        public async Task<int> DeletePurchaseReturn_h(int id)
        {
            return await purchaseReturn_HRepository.DeletePurchaseReturn_h(id);
        }

        //高级查询
        public async Task<FenYe<PurchaseReturn_h>> GetAdvancedPurchaseReturn_h(FenYe<PurchaseReturn_h> fenYe, string? code, string? starttotal, string? endtotal, string? startdate, string? enddate, string? startnum, string? endnum, int? status, int? sup, string? suplink, string? purcode, int? dep, int? user, string? createname, string? startcreatetime, string? endcreatetime, string? approvername, string? startapprovertime, string? endapprovertime)
        {
            return await purchaseReturn_HRepository.GetAdvancedPurchaseReturn_h(fenYe, code, starttotal, endtotal, startdate, enddate, startnum, endnum, status, sup, suplink, purcode, dep, user, createname, startcreatetime, endcreatetime, approvername, startapprovertime, endapprovertime);
        }


        //查询所有单据
        public async Task<List<PurchaseReturn_h>> GetAllPurchaseReturn_h()
        {
            return await purchaseReturn_HRepository.GetAllPurchaseReturn_h();
        }


        //分页查询进货退货单
        public async Task<FenYe<PurchaseReturn_h>> GetPurchaseReturn_h(FenYe<PurchaseReturn_h> fenYe, string? code, int? status, int? sup, string? starttime, string? endtime)
        {
            return await purchaseReturn_HRepository.GetPurchaseReturn_h(fenYe,code,status,sup,starttime,endtime);
        }


        //根据编号查询信息
        public async Task<PurchaseReturn_h> GetPurchaseReturn_hByCode(string code)
        {
            return await purchaseReturn_HRepository.GetPurchaseReturn_hByCode(code);
        }


        //根据id查询信息
        public async Task<PurchaseReturn_h> GetPurchaseReturn_hById(int purtId)
        {
            return await purchaseReturn_HRepository.GetPurchaseReturn_hById(purtId);
        }

        //根据关联单号查询退货记录
        public async Task<List<PurchaseReturn_h>> GetPurchaseReturn_hs(string purcode)
        {
            return await purchaseReturn_HRepository.GetPurchaseReturn_hs(purcode);
        }


        //更新出库数及状态
        public async Task<int> UpdateNum(int purtid, int oknum, int nonum, int statu)
        {
            return await purchaseReturn_HRepository.UpdateNum(purtid, oknum, nonum, statu);
        }


        //修改
        public async Task<int> UpdatePurchaseReturn_h(UpdatePurchaseReturn_hDto updatePurchaseReturn_HDto)
        {
            PurchaseReturn_h purchaseReturn_H=mapper.Map<PurchaseReturn_h>(updatePurchaseReturn_HDto);
            return await purchaseReturn_HRepository.UpdatePurchaseReturn_h(purchaseReturn_H);
        }


        //撤销
        public async Task<int> UpdateStatus(int purtid, int status)
        {
            return await purchaseReturn_HRepository.UpdateStatus(purtid, status);
        }
    }
}
